package com.xyu.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
@Configuration
public class WebConfig implements WebMvcConfigurer {
 
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  // 对所有路径开放
               .allowedOrigins("http://192.168.127.129:8080")
               .allowedOrigins("http://192.168.127.129")// 允许的来源
               .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")  // 允许的方法
               .allowedHeaders("*")  // 允许的头信息
               .allowCredentials(true)  // 是否发送Cookie
               .maxAge(3600);  // 预检请求的缓存时间
    }
}